
#ifndef _CAN_CARD_P_CAN_H_
#define _CAN_CARD_P_CAN_H_

#include "CanCard.h"
#include <windows.h>
#include "pcan_pci.h"

// defines data type PCAN_...
// PCAN_... is function pointer with calling convention on a
// funkcion CAN_... (defined in pcan_usb.h)  
typedef DWORD (__stdcall *PCAN_Init)(WORD wBTR0BTR1, int CANMsgType);
typedef DWORD (__stdcall *PCAN_Close)();
typedef DWORD (__stdcall *PCAN_Status)();
typedef DWORD (__stdcall *PCAN_Write)(TPCANMsg* pMsgBuff);
typedef DWORD (__stdcall *PCAN_Read)(TPCANMsg* pMsgBuff);
typedef DWORD (__stdcall *PCAN_VersionInfo)(LPSTR lpversioninfo);

class CanCardPCan : public GenericCanCard
{
public:
	CanCardPCan(int Carte, int Bus, bool VerboseLog, int frequency, bool isUsb=0);
	virtual ~CanCardPCan();
	virtual bool good();
	virtual bool SendMsg(unsigned int ID, unsigned short DataLen, unsigned char* Data);
	virtual bool RcvMsg(unsigned int& ID, unsigned short& DataLen, unsigned char* Data);
private:
	unsigned int GetFunctionAdress(HINSTANCE h_module);
	void check_can_err(DWORD err,  char *txtbuff);
	void check_lc_err(int err, char *txtbuff);
	void check_lc_state(int state, char *txtbuff);
	bool LoadDLL(const char* dllName);
	bool UnloadDLL();
	bool sendMB(TPCANMsg* messagebox);	// send CAN message and display error if one occured

private:
	bool IsGood;

// Handle for DLL
	HINSTANCE m_i_DLL;

// declares m_CAN_ functions mapped to dll
	PCAN_Init m_CAN_Init;
	PCAN_Close m_CAN_Close;
	PCAN_Status m_CAN_Status;
	PCAN_Write  m_CAN_Write;
	PCAN_Read m_CAN_Read;
	PCAN_VersionInfo m_CAN_VersionInfo;
};

#endif //_CAN_CARD_P_CAN_H_
